﻿#include "FITKAbaBeamOrientation.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Interface/FITKInterfaceModel/FITKModelSet.h"


void Interface::FITKAbaBeamOrientation::setModelSetID(const int id)
{
    m_setId = id;
}

int Interface::FITKAbaBeamOrientation::getModelSetID() const
{
    return m_setId;
}

std::array<double, 3> Interface::FITKAbaBeamOrientation::getN1Direction() const
{
    return m_n1Direction;
}

void Interface::FITKAbaBeamOrientation::setN1Direction(const std::array<double, 3> &dir)
{
    m_n1Direction = dir;
}

Interface::FITKAbstractModel *Interface::FITKAbaBeamOrientation::getPart()
{
    FITKModelSet* set = FITKDATAREPO->getTDataByID<FITKModelSet>(m_setId);
    if (set == nullptr) return nullptr;
    return set->getAbstractModel();
}

bool Interface::FITKAbaBeamOrientation::copy(FITKAbstractDataObject *obj)
{
    bool ok = Core::FITKAbstractDataObject::copy(obj);
    if (!ok)
        return false;
    FITKAbaBeamOrientation* o = dynamic_cast<FITKAbaBeamOrientation*>(obj);
    if (o == nullptr)
        return false;
    m_setId = o->m_setId;
    m_n1Direction = o->m_n1Direction;
    return true;
}

Interface::FITKAbaBeamOrientation *Interface::FITKAbaBeamOrientationManager::getBeamOrientation(int setID)
{
    const int n = this->getDataCount();
    for (int i =0; i<n; ++i)
    {
        FITKAbaBeamOrientation* ori = this->getDataByIndex(i);
        if(ori == nullptr)
            continue;
        if (setID == ori->getModelSetID())
            return ori;
    }
    return nullptr;
}
